package com.siha_back.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.siha_back.entity.dto.PageBean;
import com.siha_back.entity.dto.PushNotifications;
import com.siha_back.entity.dto.Resume;
import com.siha_back.mapper.PushNotificationsMapper;
import com.siha_back.service.PushNotificationsService;
import com.siha_back.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import java.util.List;
import java.util.Map;


/**
 * 推送消息表(PushNotifications)表服务实现类
 *
 * @author makejava
 * @since 2025-04-16 10:41:31
 */
@Service
public class PushNotificationsServiceImpl implements PushNotificationsService {
    @Autowired
    private PushNotificationsMapper pushNotificationsMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PushNotifications queryById(Long id) {
        return this.pushNotificationsMapper.queryById(id);
    }

    @Override
    public List<PushNotifications> list() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer major = (Integer) map.get("major");
        System.out.println(major);
        return pushNotificationsMapper.list(major);
    }

    @Override
    public List<PushNotifications> queryByNotificationId(Integer notificationId) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer major = (Integer) map.get("major");
        System.out.println(major);
        return pushNotificationsMapper.queryByNotificationId(major,notificationId);
    }

    @Override
    public PageBean<PushNotifications> list1(Integer pageNum, Integer pageSize, Integer notificationId, String title) {
        PageBean<PushNotifications> pb = new PageBean<>();
        //开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        List<PushNotifications> list= pushNotificationsMapper.list1(notificationId,title);
        System.out.println(list);
        com.github.pagehelper.Page<PushNotifications> pageInfo=(Page<PushNotifications>) list;
        pb.setTotal(pageInfo.getTotal());
        pb.setItems(pageInfo.getResult());
        return pb;
    }

}
